function [ g ] = calc_g( w,x,i,f,usedsegs )
    g = zeros(2,2);
    strs = ['0' '1'];
    ind = find(usedsegs>0);
    for n=0:3
        for y1=1:size(g,1)
            for iter=1:size(ind)
                j=ind(iter) + n*size(usedsegs,1);
                %ll_feat_func( y, x, i, seg, bchar )
                test = ( w(j)*ll_feat_func(strs(y1),strs(1),x,i,f{j,1},f{j,2}));
                g(y1,1) = g(y1,1) + test;

                test = ( w(j)*ll_feat_func(strs(y1),strs(2),x,i,f{j,1},f{j,2}));
                g(y1,2) = g(y1,2) + test;
            end
        end
    end
end
